<?php
/**
 * Created by PhpStorm.
 * User: Edik
 * Date: 2016/3/3
 * Time: 10:19
 */

namespace Admin\Controller;


use Admin\Model\NewsModel;

class NewsController extends AdminBaseController
{
    /********************************  新闻相关  **************************************************/

    function lst(){
        $model = M();

        $data = $model->query("select n.id,n.title,m.nickname,if(n.article_type = 1,'公司新闻','行业动态')type from ed_news n left join ed_member m on n.user_id = m.id WHERE article_class = 2 ");

        $this->assign("news", $data);
        $this->display();
    }

    function add(){
        if(IS_POST){
            $model = new NewsModel();
            if($model->create(I('post.'),1)){
                if($id = $model->add()){
                    $this->success("添加成功！",U('lst'));
                    exit;
                }
            }else{
                $this->error($model->getError());
            }
        }

        $this->display();
    }

    function delete(){
        $model = new NewsModel();
        if($model->delete(I('get.id'),0) != FALSE){
            $this->success("删除成功！",U('lst'));
            exit;
        }else{
            $this->error($model->getError());
        }
    }

    function edit(){
        $model = new NewsModel();
        if(IS_POST){
            if($model->create(I('post.'), 2))
            {
                if($model->save() !== FALSE)
                {
                    $this->success('修改成功！', U('lst'));
                    exit;
                }
            }
            $this->error($model->getError());
        }

        $this->assign("new",$model->find(I('get.id')));
        $this->display();
    }


    /********************************  招聘相关  **************************************************/

    function lstzp(){
        $model = M();

        $data = $model->query("select n.id,n.title,m.nickname,if(n.article_type = 0 ,'公司招聘','行业动态')type from ed_news n left join ed_member m on n.user_id = m.id WHERE article_class = 1 ");

        $this->assign("news", $data);
        $this->display();
    }

    function addzp(){
        if(IS_POST){



            $model = new NewsModel();
            if($model->create(I('post.'),1)){
                if($id = $model->add()){
                    $this->success("添加成功！",U('lstzp'));
                    exit;
                }
            }else{
                $this->error($model->getError());
            }
        }

        $this->display();
    }

    function deletezp(){
        $model = new NewsModel();
        if($model->delete(I('get.id'),0) != FALSE){
            $this->success("删除成功！",U('lstzp'));
            exit;
        }else{
            $this->error($model->getError());
        }
    }

    function editzp(){
        $model = new NewsModel();
        if(IS_POST){
            if($model->create(I('post.'), 2))
            {
                if($model->save() !== FALSE)
                {
                    $this->success('修改成功！', U('lstzp'));
                    exit;
                }
            }
            $this->error($model->getError());
        }

        $this->assign("new",$model->find(I('get.id')));
        $this->display();
    }

}